var t = getApp(), o = require("../../../mybehaviors/location/location");

Page({
    behaviors: [ o ],
    data: {
        city: "",
        cakeCity: "",
        total: 0,
        clicktype: "",
        optionsId: "",
        goodsDetails: {},
        optionsObj: {},
        timeData: {},
        beginStatus: 0,
        goodsId: "",
        shopList: [],
        iPnoneBottomBol: !1,
        specsShow: !1,
        cakeGoods: {},
        supplyCakeGoods: {},
        getGoods: {},
        groupCode: {},
        pluginSetting: {},
        description: "",
        brand: {
            id: 179,
            name: "测试品牌",
            logo: "1"
        },
        distance: 0,
        cakeGoodsOption: [],
        shipAreaType: "",
        btnData2: {
            over_top: 450,
            icon_url: "https://www.yunzmall.com//min_img/bc_eweima.png"
        },
        btnData: {
            over_top: 500,
            icon_url: "https://www.yunzmall.com//min_img/icon-fontclass-zhiding.png"
        },
        showKefu: !1
    },
    onLoad: function(o) {
        if (o.id && this.setData({
            goodsId: Number(o.id),
            city: o.city,
            cakeCity: o.city
        }), o.scene) {
            var e = decodeURIComponent(o.scene);
            if (console.log(e), e) {
                var i = [];
                i = e.split(",");
                for (var a = 0; a < i.length; a++) {
                    var s = [];
                    if ("id" == (s = i[a].split("="))[0]) {
                        var n = s[1].split("/");
                        console.log(n), this.setData({
                            goodsId: n[0]
                        });
                    } else "mid" == s[0] ? t._setMid(s[1]) : this.goodsdetails();
                }
            }
        } else o.mid && t._setMid(o.mid);
        this.goodsdetails(), this.getiPnoneBottom();
    },
    goodsdetails: function() {
        var o = this, e = {
            id: this.data.goodsId,
            basic_info: 1
        }, i = t.getNetAddresss("goods.goods.get-goods-page");
        t._postNetWork({
            url: i,
            data: e,
            success: function(e) {
                var i = e.data;
                if (1 == i.result) {
                    var a, s, n, d, c, l, u, r, p, g, h, v, _ = i.data.get_goods, m = null === (a = i.data) || void 0 === a || null === (s = a.plugin) || void 0 === s ? void 0 : s.yz_supply_cake, y = null === (n = i.basic_info) || void 0 === n ? void 0 : n.plugin_setting, f = null === (d = i.data) || void 0 === d || null === (c = d.plugin) || void 0 === c ? void 0 : c.group_code, w = null == m || null === (l = m.data) || void 0 === l ? void 0 : l.yz_supply_cake_goods, k = w.has_many_yz_supply_cake_goods_option[0], S = k.promotion_end_at || "", D = null == _ ? void 0 : _.content.replace(/<img/g, '<img style="max-width:100%;height:auto;"');
                    o.endTimeSpecs(k), o.setData({
                        getGoods: _,
                        pluginSetting: y,
                        cakeGoods: null == m ? void 0 : m.data,
                        supplyCakeGoods: w,
                        groupCode: f,
                        promotionEndTime: o.endTimeFun(S),
                        cakeGoodsOption: w.has_many_yz_supply_cake_goods_option,
                        beginStatus: o.endTimeSpecs(k),
                        optionsObj: _.has_many_options[0],
                        "goodsDetails.content": D,
                        customer_open: "1" == (null === (u = i.data.customer_service) || void 0 === u ? void 0 : u.customer_open),
                        cservice: null === (r = i.data.customer_service) || void 0 === r ? void 0 : r.cservice,
                        service_QRcode: null === (p = i.data.customer_service) || void 0 === p ? void 0 : p.service_QRcode,
                        service_mobile: null === (g = i.data.customer_service) || void 0 === g ? void 0 : g.service_mobile
                    }), 1 !== (null == y || null === (h = y.yz_supply_cake) || void 0 === h ? void 0 : h.is_ios_sell) && "1" !== (null == y || null === (v = y.yz_supply_cake) || void 0 === v ? void 0 : v.is_ios_sell) || ("ios" === t.isIosOrAndroid() && o.setData({
                        beginStatus: -1
                    }), wx.getSystemInfo({
                        success: function(t) {
                            t.system.indexOf("iOS") > -1 && o.setData({
                                beginStatus: -1
                            });
                        }
                    }));
                } else wx.showModal({
                    content: i.msg,
                    success: function(t) {
                        t.confirm && wx.navigateBack({
                            delta: 1
                        });
                    }
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    endTimeFun: function(t) {
        return new Date(t).getTime() - new Date().getTime();
    },
    getRule: function() {
        var o = this, e = {
            city: this.data.cakeCity,
            goods_id: this.data.goodsId
        }, i = t.getNetAddresss("plugin.yz-supply-cake.frontend.index.index.getRule");
        t._getNetWork({
            url: i,
            data: e,
            success: function(t) {
                var e = t.data;
                if (1 == e.result) {
                    var i, a, s;
                    if (200 !== e.data.code) return wx.showToast({
                        icon: "none",
                        title: e.data.msg,
                        duration: 1500
                    }), void o.setData({
                        description: e.data.msg
                    });
                    var n = e.data;
                    if (o.setData({
                        description: null === (i = n.data) || void 0 === i ? void 0 : i.description,
                        shipAreaType: null === (a = n.data) || void 0 === a ? void 0 : a.ship_area_type,
                        shopList: null === (s = n.data) || void 0 === s ? void 0 : s.shop
                    }), "2" === o.data.shipAreaType || 2 === o.data.shipAreaType) {
                        var d, c = (JSON.parse(null === (d = n.data) || void 0 === d ? void 0 : d.ship_rule) || {}).non_default || {}, l = "";
                        for (var u in c) console.log(u), l = c[u].distance;
                        o.setData({
                            distance: 1e3 * l
                        });
                    }
                } else wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    deliveryClick: function() {
        wx.navigateTo({
            url: "/packageF/sachertorte/deliveryArea/deliveryArea?goodsId=".concat(this.data.goodsId, "&city=").concat(this.data.cakeCity)
        });
    },
    imgH: function(t) {
        var o = wx.getSystemInfoSync().windowWidth * t.detail.height / t.detail.width + "px";
        this.setData({
            Hei: o
        });
    },
    onTimeChange: function(t) {
        this.setData({
            timeData: t.detail
        });
    },
    gotoMember: function() {
        wx.reLaunch({
            url: "/packageG/member_v2/member_v2"
        });
    },
    postShow: function(t) {
        this.setData({
            posterShow: !0,
            showSahre: !1
        });
    },
    posterClick: function() {
        this.setData({
            posterShow: !0
        });
    },
    posterClose: function() {
        this.setData({
            posterShow: !1
        });
    },
    onReady: function() {
        var t = this;
        try {
            this._getLocation(function(o, e) {
                var i = o.address_component.city;
                t.data.cakeCity || t.setData({
                    cakeCity: i
                }), t.getRule();
            });
        } catch (t) {
            console.log(t), this.getRule();
        }
    },
    getiPnoneBottom: function() {
        try {
            wx.getStorageSync("iPhoneBottom") && this.setData({
                iPnoneBottomBol: !0
            });
        } catch (t) {}
    },
    onService: function() {
        this.setData({
            showKefu: !0
        });
    },
    onIndex: function() {
        wx.navigateTo({
            url: "/packageF/sachertorte/sachertorteIndex/sachertorteIndex"
        });
    },
    specificationOn: function() {
        this.setData({
            specsShow: !0
        });
    },
    cakeGoodsBuy: function() {
        this.setData({
            specsShow: !0
        });
    },
    backOn: function() {
        wx.navigateBack({
            delta: 1
        });
    },
    toGroupCode: function() {
        "home" === this.data.groupCode.jump_mode ? wx.reLaunch({
            url: "/packageE/groupCode/groupCode"
        }) : this.data.groupCode.code_mini_url && wx.navigateTo({
            url: this.data.groupCode.code_mini_url
        });
    },
    close_yz_specs_popup: function(t) {
        this.setData({
            specsShow: !1
        });
    },
    selectSpecsOn: function(o) {
        var e, i, a, s, n, d, c, l = this, u = o.detail, r = u.clicktype, p = u.goodsCount, g = u.optionsId, h = this.data.cakeGoodsOption.find(function(t, o) {
            return t.option_id === g;
        }), v = null === (e = this.data.getGoods) || void 0 === e ? void 0 : e.has_many_options.find(function(t, o) {
            return t.id === g;
        }), _ = this.endTimeFun((null == h ? void 0 : h.promotion_end_at) || "") || "";
        this.setData({
            optionsObj: v,
            clicktype: r,
            total: p,
            optionsId: g,
            beginStatus: this.endTimeSpecs(h),
            promotionEndTime: _
        }), 0 === p && this.setData({
            beginStatus: -1
        }), console.log("1111111111"), console.log(null === (i = this.data.pluginSetting) || void 0 === i || null === (a = i.yz_supply_cake) || void 0 === a ? void 0 : a.is_ios_sell), 
        1 !== (null === (s = this.data.pluginSetting) || void 0 === s || null === (n = s.yz_supply_cake) || void 0 === n ? void 0 : n.is_ios_sell) && "1" !== (null === (d = this.data.pluginSetting) || void 0 === d || null === (c = d.yz_supply_cake) || void 0 === c ? void 0 : c.is_ios_sell) || ("ios" === t.isIosOrAndroid() && this.setData({
            beginStatus: -1
        }), wx.getSystemInfo({
            success: function(t) {
                t.system.indexOf("iOS") > -1 && (l.setData({
                    beginStatus: -1
                }), console.log(l.data.beginStatus));
            }
        }));
    },
    submitAction: function() {
        if (1 != this.data.getGoods.has_option || this.data.optionsId) if (1 === this.data.clicktype) {
            this.setData({
                specsShow: !1
            });
            var t = "&goodsId=".concat(this.data.goodsId, "&optionsId=").concat(this.data.optionsId, "&total=").concat(this.data.total, "&city=").concat(this.data.cakeCity);
            wx.navigateTo({
                url: "/packageD/buy/myOrder_v2/myOrder_v2?tag=cake" + t
            });
        } else this.setData({
            specsShow: !1
        }); else wx.showToast({
            icon: "none",
            title: "规格id不可为空，请选择规格！",
            duration: 1500
        });
    },
    endTimeSpecs: function(t) {
        var o = null == t ? void 0 : t.promotion_end_at, e = "";
        o && (new Date(o) > new Date().getTime() && (e = 2));
        return e;
    },
    brandNav: function(t) {
        var o = t.currentTarget.dataset.brandid;
        wx.navigateTo({
            url: "/packageF/sachertorte/classify/classify?brandId=".concat(o, "&city=").concat(this.data.cakeCity)
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        var t, o = {
            title: this.data.getGoods.title,
            path: "/packageF/sachertorte/sachertorteGoods/sachertorteGoods?id=".concat(this.data.goodsId),
            imageUrl: null === (t = this.data.getGoods) || void 0 === t ? void 0 : t.thumb_url[0]
        };
        return {
            title: o.title,
            path: o.path,
            imageUrl: o.imgUrl
        };
    }
});